<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useMemberStore } from '@/stores/modules/member'

// 状态管理
const memberStore = useMemberStore()

// 模拟用户数据
const userInfo = ref({
  avatar: '',
  nickname: '',
  balance: 0,
})
const handleRecharge = () => {
  uni.navigateTo({
    url: '/pages/recharge/recharge',
  })
}

onMounted(() => {
  if (!memberStore.profile) {
    uni.showToast({
      title: '请先登录',
      icon: 'none',
    })
  }
  Object.assign(userInfo.value, memberStore.profile)
})
</script>

<template>
  <view class="my-container">
    <!-- 用户信息卡片 -->
    <view class="user-card">
      <view class="user-info">
        <image class="avatar" :src="userInfo.avatar" mode="aspectFill" />
        <view class="info">
          <text class="nickname">{{ userInfo.nickname }}</text>
          <view class="balance">
            <text class="label">剩余余额</text>
            <text class="amount">¥{{ userInfo.balance }}</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 功能列表 -->
    <view class="menu-list">
      <view class="menu-item">
        <text class="iconfont icon-wallet"></text>
        <text class="title" @click="handleRecharge">充值</text>
        <text class="iconfont icon-arrow-right"></text>
      </view>
      <view class="menu-item">
        <text class="iconfont icon-history"></text>
        <text class="title">使用记录</text>
        <text class="iconfont icon-arrow-right"></text>
      </view>
      <view class="menu-item">
        <text class="iconfont icon-settings"></text>
        <text class="title">设置</text>
        <text class="iconfont icon-arrow-right"></text>
      </view>
    </view>
  </view>
</template>

<style lang="scss">
.my-container {
  min-height: 100vh;
  background-color: #f5f5f5;
  padding-bottom: env(safe-area-inset-bottom);
}

.user-card {
  background: linear-gradient(135deg, #007aff, #00b4db);
  padding: 40rpx 30rpx;
  margin-bottom: 20rpx;
  color: #fff;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 30rpx;
}

.avatar {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  border: 4rpx solid rgba(255, 255, 255, 0.3);
}

.info {
  flex: 1;
}

.nickname {
  font-size: 36rpx;
  font-weight: 600;
  margin-bottom: 16rpx;
  display: block;
}

.balance {
  display: flex;
  align-items: baseline;
  gap: 10rpx;
}

.label {
  font-size: 24rpx;
  opacity: 0.9;
}

.amount {
  font-size: 40rpx;
  font-weight: 600;
}

.menu-list {
  background: #fff;
  border-radius: 20rpx;
  margin: 0 20rpx;
  overflow: hidden;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 30rpx;
  border-bottom: 1rpx solid #f5f5f5;

  &:last-child {
    border-bottom: none;
  }

  .iconfont {
    font-size: 40rpx;
    margin-right: 20rpx;
    color: #666;
  }

  .title {
    flex: 1;
    font-size: 28rpx;
    color: #333;
  }

  .icon-arrow-right {
    color: #999;
    font-size: 24rpx;
  }
}

/* 暗黑模式适配 */
@media (prefers-color-scheme: dark) {
  .my-container {
    background-color: #1a1a1a;
  }

  .menu-list {
    background: #2a2a2a;
  }

  .menu-item {
    border-color: #333;

    .iconfont {
      color: #999;
    }

    .title {
      color: #fff;
    }
  }
}
</style>
